﻿

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using EShop.Common;
using EShop.Model;
//using EShop.Common;

namespace EShop.Client
{
    public partial class frmBase : Form
    {
        protected static Sunisoft.IrisSkin.SkinEngine se =null;

        public frmBase()
        {
            InitializeComponent();
        }


        //当前登录员工信息
        protected static EshopConfigInfo oShopConfigInfo;
        protected PermissionEnum formPermission = PermissionEnum.None;
        protected PermissionEnum userPermission = PermissionEnum.None;

        protected void SetSkin()
        {
            se = new Sunisoft.IrisSkin.SkinEngine();
            se.SkinAllForm = true;
        }

        /// <summary>
        /// 检查是否有相应的权限
        /// </summary>
        /// <param name="UserPermission">用户权限</param>
        /// <param name="PermissionFlag">要匹配的权限</param>
        /// <returns></returns>
        protected bool CheckPermission(PermissionEnum UserPermission, PermissionEnum PermissionFlag)
        {
            return (UserPermission & PermissionFlag) == PermissionFlag ? true : false;
        }

        /// <summary>
        /// 日志记录
        /// </summary>
        /// <param name="logInfo">记录数据</param>
        protected void LogWrite(Exception ex)
        {
            #if DEBUG
                        MessageBox.Show(ex.Message);
            #endif

            //TODO: 加入ex详细信息
            string logInfo = ex.ToString();
            if (oShopConfigInfo != null)//加入当前用户信息
                logInfo = string.Format("当前登录信息：{0}\r\n{1}", oShopConfigInfo.LoginID, logInfo);

            log.Write(logInfo);
        }

        #region 放置系统设置公共参数

        /// <summary>
        /// 锁屏密码
        /// </summary>
        protected static string lockPassword = string.Empty;


        protected static int iMaxPageSize;
        #endregion

        private void frmBase_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// TextBox控件异步赋值方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnTextBoxEndueValueEvent(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            TextBox txtTmp = (TextBox)e.ControlName;
            if (txtTmp.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else txtTmp.Text = e.SetValue.ToString();
        }

        protected virtual void OnLableEndueValueEvent(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            Label lblTmp = (Label)e.ControlName;
            if (lblTmp.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else lblTmp.Text = e.SetValue.ToString();
        }

        protected virtual void OnComboBoxEndueValueEvent(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            ComboBox cbbTmp = (ComboBox)e.ControlName;
            if (cbbTmp.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else cbbTmp.SelectedIndex = (int)e.SetValue;
        }

        protected virtual void OnDataGridViewEndueValueEvent(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            DataGridView dgvTmp = (DataGridView)e.ControlName;
            if (dgvTmp.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else dgvTmp.Rows.Add((DataGridViewRow)e.SetValue);
        }

        protected virtual void OnBindingSourceEndueValueEvent(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            BindingSource tmpBds = (BindingSource)e.ControlName;
            if (this.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else tmpBds.DataSource = e.SetValue;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">e.SetValue is TreeNode Type</param>
        protected virtual void OnTreeViewEndueValueEvent(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            TreeView tvTmp = (TreeView)e.ControlName;
            if (tvTmp.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else tvTmp.Nodes.Add((TreeNode)e.SetValue);
        }

        protected virtual void OnToolStripStatusLabelEndueValueEvent(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            ToolStripStatusLabel tsslblTmp = (ToolStripStatusLabel)e.ControlName;
            if (this.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else tsslblTmp.Text = e.SetValue.ToString();
        }

        protected virtual void OnToolStripTextBoxEndureValueEvent(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            ToolStripTextBox tstxtTmp = (ToolStripTextBox)e.ControlName;
            if (this.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else tstxtTmp.Text = e.SetValue.ToString();
        }

        protected virtual void OnToolStripLabelEndureValue(object sender, AsyncMethod.EndueValueEventArgs e)
        {
            ToolStripLabel tslblTmp = (ToolStripLabel)e.ControlName;
            if (this.InvokeRequired) this.BeginInvoke(e.OnControlEndueValue, sender, e);
            else tslblTmp.Text = e.SetValue.ToString();
        }
    }
}
